﻿namespace ElisVK.Data.AudioSources
{
    using System.Collections.ObjectModel;
    using System.Net;
    using System.Text;
    using Utils;

    class VKFriendAudioSource : AudioSource
    {
        private UserInfo _userInfo;

        public VKFriendAudioSource(UserInfo userInfo) : base(string.Format("{0} {1}", userInfo.FirstName, userInfo.LastName))
        {
            _userInfo = userInfo;
        }

        public override ObservableCollection<Audio> GetAudios()
        {
            var audios = new ObservableCollection<Audio>();

            if (_userInfo.UserID == 0)
            {
                return audios;
            }

            var buff = VKHelper.DownloadData(
                string.Format("https://api.vkontakte.ru/method/audio.get.xml?uid={0}&access_token={1}", _userInfo.UserID, App.SessionInfo.AccessToken));

            audios = new ObservableCollection<Audio>(VKHelper.ParseAudiosFromXML(Encoding.UTF8.GetString(buff)));

            return audios;
        }
    }
}
